﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MadProps.Validation
{
    class CompositeValidator : IValidator
    {
        readonly IList<IValidator> validators;
        internal CompositeValidator(IEnumerable<IValidator> validators)
        {
            this.validators = validators.ThrowIfNull("validators").ToList();
        }

        public ValidationResult Validate(ValidationArgs args)
        {
            foreach (var validator in validators)
            {
                var result = validator.Validate(args);
                if (!result.IsValid)
                {
                    return ValidationResult.Error(result.Messages);
                }
            }
            return ValidationResult.Success();
        }
    }
}
